﻿@{
    ViewBag.Title = " 创建用户";
    Layout = null;
}
<div id="user_create_container" class="container">
    <form id="user_create_from" method="POST">
        <table>
            <tr>
                <th>
                    账号:
                </th>
                <td>
                    <input type="text" id="user_create_account" name="Account" />
                </td>
            </tr>
            <tr>
                <th>
                    密码:
                </th>
                <td>
                    <input type="password" id="user_create_password" name="PassWord" />
                </td>
            </tr>
            <tr>
                <th>
                    确认密码:
                </th>
                <td>
                    <input type="password" id="user_create_confirm" />
                </td>
            </tr>
            <tr>
                <th>
                    用户名:
                </th>
                <td>
                    <input type="text" id="user_create_username" name="UserName" />
                </td>
            </tr>
            <tr>
                <th>
                    手机号:
                </th>
                <td>
                    <input type="text" id="user_create_mobile" name="Mobile" />
                </td>
            </tr>
            <tr>
                <th>
                    邮箱:
                </th>
                <td>
                    <input type="text" id="user_create_email" name="Email" />
                </td>
            </tr>
            <tr>
                <th>
                    QQ:
                </th>
                <td>
                    <input type="text" id="user_create_qq" name="Qq" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <a href="javascript:;" id="user_create_cancel" style="margin-right: 10px;"></a>
                    <a href="javascript:;" id="user_create_submit">
                    </a>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    (function () {
        Oneworks.CreatePage('UserCreate', {
            settings: {
                formurl: '/Api/User/Create'
            },
            commons: {
                getFormData: function () {
                    var that = Oneworks.page['UserCreate'], controls = that.controls;
                    return {
                        Account: controls.account.val(),
                        PassWord: controls.password.val(),
                        Confirm: controls.confirm.val(),
                        UserName: controls.username.val(),
                        Mobile: controls.mobile.val(),
                        Email: controls.email.val(),
                        Qq: controls.qq.val()
                    };
                },
            },
            controls: {
                container: $('#user_create_container'),
                form: $('#user_create_from'),
                submit: $('#user_create_submit'),
                cancel: $('#user_create_cancel'),
                account: $('#user_create_account'),
                password: $('#user_create_password'),
                confirm: $('#user_create_confirm'),
                username: $('#user_create_username'),
                mobile: $('#user_create_mobile'),
                email: $('#user_create_email'),
                qq: $('#user_create_qq'),
            },
            events: {
                onSubmit: function () {
                    Oneworks.page.UserCreate.controls.form.submit();
                },
                onCloase: function () { },
                onSuccess: function () { },
                onFailure: function () { }
            }
        }, function () {
            var that = this,
                controls = that.controls,
                setting = that.settings,
                events = that.events;
            controls.init = function () {
                controls.form.form({
                    url: setting.formurl,
                    onSubmit: function () {
                        var isValid = controls.form.form('validate');
                        if (isValid)
                            controls.container.Easyui().mark();
                        return isValid;
                    },
                    success: function (data) {                       
                        var r = $.parseJSON(data);                       
                        if (r.Status == 1) {                         
                            controls.form.form('clear');
                            events.onSuccess(r);
                        } else {
                            events.onFailure(r);
                        }
                        controls.container.Easyui().mark(true);
                    }
                });
                controls.account.validatebox({ required: true, validType: ['remote["/Api/User/ExistsAccount","acction"]', 'length[6,20]'] });
                controls.password.validatebox({ required: true, validType: 'length[6,20]' });
                controls.confirm.validatebox({ required: true, validType: 'equals["#user_create_password"]' });
                controls.username.validatebox({ required: true, validType: 'length[6,20]' });
                controls.qq.validatebox({ validType: 'qq' });
                controls.email.validatebox({ validType: 'email' });
                controls.mobile.validatebox({ validType: 'mobile' });
                controls.submit.linkbutton({ text: '保存' });
                controls.cancel.linkbutton({ text: '取消' });
                var p = controls.container.parent(),
                    h = p.height(),
                    w = p.width();
                controls.container.css({
                    width: w,
                    height: h
                });
            };
            events.init = function () {
                controls.submit.click(function () {
                    events.onSubmit();
                });
                controls.cancel.click(function () {
                    events.onClose();
                });
            };
            controls.init();
            events.init();
        });
    }());
</script>
